package net.tv90.bfmccore.helper;

import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;

import java.util.Objects;

public class ItemHelper {

    //将英文id转为数字id
    public static int itemToID(Material itemName) {
        return new ItemStack(itemName).getTypeId();
    }

    //将数字id转为英文id
    public static Material idToItem(short id) {
        return new ItemStack(id).getType();
    }

    //将指定字符串转为英文id
    public static Material stringToMaterial(String s) {
        if(Objects.equals(s, "null") || s == null) return Material.AIR;
        try {
            return Material.valueOf(s);
        } catch (Exception e) {
            System.out.println("No such material! ( " + s + " )");
            return Material.AIR;
        }
    }

}
